package com.mofang.powerdekorhelper.persenter;

import com.mofang.powerdekorhelper.base.BasePresent;
import com.mofang.powerdekorhelper.model.JHelpAndFeedback;
import com.mofang.powerdekorhelper.utils.UrlTools;
import com.mofang.powerdekorhelper.utils.http.InitRetrofit;
import com.mofang.powerdekorhelper.utils.http.RetrofitSerives;
import com.mofang.powerdekorhelper.view.HelpAndFeedBackView;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by luofei on 2017/8/19 0019.
 */

public class HelpAndFeedBackPerenster extends BasePresent<HelpAndFeedBackView> {

    public void getJHelpAndFeedback(){

        view.showProgress();

        RetrofitSerives retrofitSerives = InitRetrofit.getInstance().getRetrofit(UrlTools.SellerAddress);
        Call<JHelpAndFeedback> call = retrofitSerives.getJHelpAndFeedback();
        call.enqueue(new Callback<JHelpAndFeedback>() {
            @Override
            public void onResponse(Call<JHelpAndFeedback> call, Response<JHelpAndFeedback> response) {
                if (response.isSuccessful()) {
                    view.setHelpAndFeedBackInfo(response.body());
                    view.hideProgress();
                } else {
                    view.onError("请求失败，请重试");
                    view.hideProgress();
                }
            }

            @Override
            public void onFailure(Call<JHelpAndFeedback> call, Throwable t) {
                view.onError("请求服务器异常，稍候再试");
                view.hideProgress();
            }
        });
    }


    @Override
    public void stopRequest() {

    }
}
